package com.kede.app.rest;

import com.kede.annotation.Log;
import com.kede.app.domain.OperatUser;
import com.kede.app.service.OperatUserService;
import com.kede.app.service.dto.OperatUserQueryCriteria;
import org.springframework.data.domain.Pageable;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

/**
* @author Pr.li
* @date 2023-08-19
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "operatUser管理")
@RequestMapping("/api/operatUser")
public class OperatUserController {

    private final OperatUserService operatUserService;

    /**
     * 导出数据
     **/
    @Log("导出数据")
    @ApiOperation("导出数据")
    @GetMapping(value = "/download")
    @PreAuthorize("@el.check('operatUser:list')")
    public void exportOperatUser(HttpServletResponse response, OperatUserQueryCriteria criteria) throws IOException {
        operatUserService.download(operatUserService.queryAll(criteria), response);
    }

    /**
    * 查询operatUser
    **/
    @GetMapping
    @Log("查询operatUser")
    @ApiOperation("查询operatUser")
    @PreAuthorize("@el.check('operatUser:list')")
    public ResponseEntity<Object> queryOperatUser(OperatUserQueryCriteria criteria, Pageable pageable){
        return new ResponseEntity<>(operatUserService.queryAll(criteria,pageable),HttpStatus.OK);
    }

    /**
    * 新增operatUser
    **/
    @PostMapping
    @Log("新增operatUser")
    @ApiOperation("新增operatUser")
    @PreAuthorize("@el.check('operatUser:add')")
    public ResponseEntity<Object> createOperatUser(@Validated @RequestBody OperatUser resources){
        return new ResponseEntity<>(operatUserService.create(resources),HttpStatus.CREATED);
    }


    /**
    * 修改operatUser
    **/
    @PutMapping
    @Log("修改operatUser")
    @ApiOperation("修改operatUser")
    @PreAuthorize("@el.check('operatUser:edit')")
    public ResponseEntity<Object> updateOperatUser(@Validated @RequestBody OperatUser resources){
        operatUserService.update(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }


    /**
    * 删除operatUser
    **/
    @DeleteMapping
    @Log("删除operatUser")
    @ApiOperation("删除operatUser")
    @PreAuthorize("@el.check('operatUser:del')")
    public ResponseEntity<Object> deleteOperatUser(@RequestBody String[] ids) {
        operatUserService.deleteAll(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }
}